package net.scalan.jpa.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

@Entity
public class DBLogicalStationObject implements Serializable {

    private static final long serialVersionUID = 1L;

    //==========================================================================
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    //==========================================================================
    @Column
    private String name;

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    //==========================================================================
    @Column
    private Long dt;

    /**
     * @return the dt
     */
    public Long getDt() {
        return dt;
    }

    /**
     * @param dt the dt to set
     */
    public void setDt(Long dt) {
        this.dt = dt;
    }

    //--------------------------------------------------------------------------
    @Column
    private Integer stateValue;

    /**
     * @return the stateValue
     */
    public Integer getStateValue() {
        return (int) (Math.random() * 9);//stateValue;
    }

    /**
     * @param stateValue the stateValue to set
     */
    public void setStateValue(Integer stateValue) {
        this.stateValue = stateValue;
    }

    //==========================================================================
    @ManyToOne
    private DBStation station;

    /**
     * @return the station
     */
    public DBStation getStation() {
        return station;
    }

    /**
     * @param station the station to set
     */
    public void setStation(DBStation station) {
        this.station = station;
    }

    //==========================================================================
    @OneToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE}, fetch=FetchType.LAZY)
    @JoinColumn(name = "stationObject_id", referencedColumnName = "id")
    private List<DBLogicalStationObjectHistory> history = new ArrayList<DBLogicalStationObjectHistory>();

    /**
     * @return the history
     */
    public List<DBLogicalStationObjectHistory> getHistory() {
        return history;
    }
    
    //==========================================================================
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof DBLogicalStationObject)) {
            return false;
        }
        DBLogicalStationObject other = (DBLogicalStationObject) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "net.scalan.jpa.model." + this.getClass().getName() + "[id=" + id + "]";
    }
}
